package com.edu.d9_map_impl;

public class Apple implements Comparable<Apple> {
    private String name;
    private String coolor;
    private double price;
    private int weight;

    public Apple() {
    }

    public Apple(String name, String coolor, double price, int weight) {
        this.name = name;
        this.coolor = coolor;
        this.price = price;
        this.weight = weight;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getCoolor() {
        return coolor;
    }

    public void setCoolor(String coolor) {
        this.coolor = coolor;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public int getWeight() {
        return weight;
    }

    public void setWeight(int weight) {
        this.weight = weight;
    }

    @Override
    public String toString() {
        return "Apple{" +
                "name='" + name + '\'' +
                ", coolor='" + coolor + '\'' +
                ", price=" + price +
                ", weight=" + weight +
                '}';
    }

    /**
     * 方法类一：
     * 自定义比较规则
     * compaerTo
     * @param apple
     * @return
     */
    @Override
    public int compareTo(Apple apple) {
       /* //按照重量进行排序，但是，重量一样的它会认为成重复的进行删除
        return this.weight-apple.weight;*/
        //想要不删除，改变一下返回值
        return this.weight-apple.weight>=0?1:-1;
    }
}
